using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace OpenScrum.db
{
    public class BacklogItemTest
    {
        #region Properties

        public int BacklogItemTestId { get; set; }
        public string Description { get; set; }
        public string TestSteps { get; set; }
        public string ExpectedResult { get; set; }
        public string ActualResults { get; set; }
        public int? BacklogItemTestStatus { get; set; } // TODO: Change to enum when CF supports enums                
        public DateTime CreatedDate { get; set; }        
        public DateTime? LastUpdatedDate { get; set; }
        public int BacklogItemId { get; set; }
        //public int CreatedById { get; set; }
        //public int? OwnedById { get; set; }
        
        #endregion

        #region Navigation Properties
       
        public virtual TeamMember CreatedBy { get; set; }             
        public virtual TeamMember OwnedBy { get; set; }        
        public virtual BacklogItem BacklogItem { get; set; }

        #endregion

        #region Constructor

        public BacklogItemTest()
        {
            CreatedDate = DateTime.Now;
        }

        #endregion        
    }

    class BacklogItemTestConfiguration : EntityTypeConfiguration<BacklogItemTest>
    {
        internal BacklogItemTestConfiguration()
        {
            // required one-to-many between team member and backlog item
            this
                .HasRequired(m => m.CreatedBy)
                .WithOptional()
                .Map(m => m.MapKey("CreatedById"));

            // optional one-to-many between team member and backlog item
            this
                .HasOptional(m => m.OwnedBy)
                .WithMany()
                .Map(m => m.MapKey("OwnedById"));
            //.WillCascadeOnDelete(false); // this is needed for two required columns referencing one table
        }
    }
}